********************************************************************
***** EMPIRICAL ANALYSIS:  GENDER AND COLLABORATION (LORENZO DUCTOR, SANJEEV GOYAL AND ANJA PRUMMER)
***** Start: 14.12.2020
***** Last change:  04.05.2021
***** CREATED BY: Lorenzo Ductor (lductor@ugr.es)   
***** OBJECTIVE: Replicate Tables 1-6 and Figures 1-3
********************************************************************



/*TABLE 1: columns 1 and 2*/
set more off
import delimited "networkgender7017.csv", clear
drop if nauthors<0
drop if year<1970

egen femaleapipaper=rowmin(femaleapi1 femaleapi2 femaleapi3 femaleapi4 femaleapi5 femaleapi6 femaleapi7)

gen decade701=1 if year<1976 & year>1970
gen decade702=1 if year>1975 & year<1981

gen decade801=1 if year<1986 & year>1980
gen decade802=1 if year>1985 & year<1991

gen decade901=1 if year<1996 & year>1990
gen decade902=1 if year>1995 & year<2001

gen decade001=1 if year<2006 & year>2000
gen decade002=1 if year>2005 & year<2011

gen decade101=1 if year<2016 & year>2010
gen decade102=1 if year>2015

foreach i in decade701 decade702 decade801 decade802 decade901 decade902 decade001 decade002 decade101 decade102{
panels articleid if `i'==1
}
panels articleid 

foreach i in decade701 decade702 decade801 decade802 decade901 decade902 decade001 decade002 decade101 decade102{
panels journalid if `i'==1
}
panels journalid 


/*TABLE 1: columns 3 and 4*/

use "auth7017fields5y.dta", clear
xtset auth year,yearly
gen decade701=1 if year<1976 & year>1970
gen decade702=1 if year>1975 & year<1981

gen decade801=1 if year<1986 & year>1980
gen decade802=1 if year>1985 & year<1991

gen decade901=1 if year<1996 & year>1990
gen decade902=1 if year>1995 & year<2001

gen decade001=1 if year<2006 & year>2000
gen decade002=1 if year>2005 & year<2011

gen decade101=1 if year<2016 & year>2010
gen decade102=1 if year>2015

foreach i in decade701 decade702 decade801 decade802 decade901 decade902 decade001 decade002 decade101 decade102{
panels auth if `i'==1 & femaleapi==1
}
panels auth if femaleapi==1

foreach i in decade701 decade702 decade801 decade802 decade901 decade902 decade001 decade002 decade101 decade102{
panels auth if `i'==1 & femaleapi==1
}
panels auth if femaleapi==0

/*TABLES 1, columns 5, 6 and 7*/	

foreach i in decade701 decade702 decade801 decade802 decade901 decade902 decade001 decade002 decade101 decade102{
mean snpapers5y if `i'==1, over(femaleapi)
}
mean snpapers5y, over(femaleapi)
/*Column 7*/
foreach i in decade701 decade702 decade801 decade802 decade901 decade902 decade001 decade002 decade101 decade102{
reg  snpapers5y femaleapi if `i'==1, cluster(auth)
}
reg  snpapers5y femaleapi, cluster(auth)


/*REPLICATING TABLE 2: Gender Differences in Performance and in Collaboration; Unadjusted and Adjusted differences*/	  
   
use auth7017fields5y,clear
xtset auth year, yearly
/*Computing Unadjusted and Adjusted differences*/
 
/*Performance measures*/
set more off 
/*Number of publications from t-4 to t*/
reg snpapers5y i.femaleapi i.t i.year sa-sz, cluster(auth)  /*total number of papers*/
margins femaleapi, atmeans 
ttest snpapers5y if e(sample), by(femaleapi) unequal
/*Number of Top5 publications from t-4 to t*/
reg snpapersAA5y i.femaleapi i.t i.year sa-sz, cluster(auth)  /*top 5*/
margins femaleapi, atmeans 
ttest snpapersAA5y if e(sample), by(femaleapi) unequal
/*AIS*/
reg saisd5y i.femaleapi i.t i.year sa-sz, cluster(auth)  /*AIS quality measure*/
margins femaleapi, atmeans
ttest saisd5y if e(sample), by(femaleapi) unequal

/*Log(AIS+1)*/
reg lsaisd5y i.femaleapi i.t i.year sa-sz, cluster(auth)  /*Log AIS quality measure*/
margins femaleapi, atmeans
ttest lsaisd5y if e(sample), by(femaleapi) unequal

/*Network measures*/
/*Degree, Adjusted*/
reg degree ddegree i.femaleapi i.year i.t sa-sz, vce(cluster auth)  
margins femaleapi, at(ddegree==0)
/*Degree, Unadjusted*/
reg degree ddegree i.femaleapi, vce(cluster auth)  
margins femaleapi, at(ddegree==0)

/*Clustering, Adjusted*/
reg clustering dclustering i.femaleapi i.year i.t sa-sz, vce(cluster auth)
margins femaleapi, at(dclustering==0)

/*Clustering, Unadjusted*/
reg clustering dclustering i.femaleapi, vce(cluster auth)
margins femaleapi, at(dclustering==0)

/*Strength Adjusted*/
reg strengthppaper dstrengthppaper i.femaleapi i.year i.t sa-sz, vce(cluster auth)
margins femaleapi, at(dstrengthppaper==0)
/*Strength Unadjusted*/
reg strengthppaper dstrengthppaper i.femaleapi, vce(cluster auth)
margins femaleapi, at(dstrengthppaper==0)


/*Coauthorship, Adjusted*/
reg coauthorship5y dcoauthorship5y i.femaleapi i.year i.t sa-sz, vce(cluster auth)
margins femaleapi, at(dcoauthorship5y==0)
/*Coauthorship, Unadjusted*/
reg coauthorship5y dcoauthorship5y i.femaleapi, vce(cluster auth)
margins femaleapi, at(dcoauthorship5y==0)
	 
/*Coauthors' characteristics*/
/* Average co-author experience, adjusted*/
reg avgcot davgcot i.femaleapi i.year i.t sa-sz, vce(cluster auth)
margins femaleapi, atmeans
/* Average co-author experience, unadjusted*/
ttest avgcot if e(sample), by(female) unequal 

/*Log(AISc+1), adjusted. AISc denotes average co-authors output*/
reg lavnetprodais dlavnetprodais i.femaleapi i.year i.t sa-sz, vce(cluster auth)
margins femaleapi, atmeans
outreg2 using Tablenetz_pols, tex dec(3) keep(femaleapi cproddl5 degree) eqdrop(lnalpha) label addtext(Career-time FE, YES, Year FE,YES, JEL codes FE, YES) 
ttest lavnetprodais if e(sample), by(female) unequal 

 
/*TABLE 3: Gender, Networks and Future # of Top 5 publications*/


/*FUTURE OUTPUT USING NUMBER OF TOP 5 PAPERS*/
label variable degreel5 "Degree t-5"
label variable clusteringl5 "Clustering t-5"
label variable strengthppaperl5 "Strength t-5"
label variable femaleapi "Female"
label variable lcaisdl5 "Past output"
label variable lavnetprodaisl5 "Avg. co-authors' Output t-5"
label variable avgcotl5 "Avg. co-authors' Experience t-5"
set more off
reg snpapersAA5y i.femaleapi degreel5 ddegreel5 dclusteringl5 dstrengthppaperl5 strengthppaperl5 clusteringl5 tpapersAAl5 sa-sz i.t i.year, vce(cluster auth)
gen es2=1 if e(sample)	   

reg snpapersAA5y i.femaleapi sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using TablefpapersAA, tex dec(3) drop(sa-sz i.t i.year) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) replace

reg snpapersAA5y i.femaleapi tpapersAAl5 sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using TablefpapersAA, tex dec(3) drop(sa-sz i.t i.year) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg snpapersAA5y degreel5 ddegreel5 i.femaleapi sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using TablefpapersAA, tex dec(3) drop(sa-sz i.t i.year ddegreel5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg snpapersAA5y degreel5 ddegreel5 i.femaleapi tpapersAAl5 sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using TablefpapersAA, tex dec(3) drop(sa-sz i.t i.year ddegreel5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg snpapersAA5y strengthppaperl5 dstrengthppaperl5 i.femaleapi sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using TablefpapersAA, tex dec(3) drop(sa-sz i.t i.year dstrengthppaperl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg snpapersAA5y strengthppaperl5 dstrengthppaperl5 i.femaleapi tpapersAAl5 sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using TablefpapersAA, tex dec(3) drop(sa-sz i.t i.year dstrengthppaperl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg snpapersAA5y clusteringl5 dclusteringl5 i.femaleapi sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using TablefpapersAA, tex dec(3) drop(sa-sz i.t i.year dclusteringl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg snpapersAA5y clusteringl5 dclusteringl5 i.femaleapi tpapersAAl5 sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using TablefpapersAA, tex dec(3) drop(sa-sz i.t i.year dclusteringl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg snpapersAA5y ddegreel5 dclusteringl5 dstrengthppaperl5 degreel5 strengthppaperl5 clusteringl5 i.femaleapi  sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using TablefpapersAA, tex dec(3) drop(sa-sz i.t i.year ddegreel5 dclusteringl5 dstrengthppaperl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 


reg snpapersAA5y ddegreel5 dclusteringl5 dstrengthppaperl5 degreel5 strengthppaperl5 clusteringl5 i.femaleapi tpapersAAl5 sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using TablefpapersAA, tex dec(3) drop(sa-sz i.t i.year ddegreel5 dclusteringl5 dstrengthppaperl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

/*testing if female dummy is different across models*/
reg snpapersAA5y femaleapi sa-sz i.t i.year if es2==1
estimates store m1
reg snpapersAA5y femaleapi tpapersAAl5 sa-sz i.t i.year if es2==1
estimates store m2
reg snpapersAA5y degreel5 ddegreel5 femaleapi sa-sz i.t i.year if es2==1
estimates store m3
reg snpapersAA5y degreel5 ddegreel5 femaleapi tpapersAAl5 sa-sz i.t i.year if es2==1
estimates store m4
reg snpapersAA5y strengthppaperl5 dstrengthppaperl5 femaleapi sa-sz i.t i.year if es2==1
estimates store m5
reg snpapersAA5y strengthppaperl5 dstrengthppaperl5 femaleapi tpapersAAl5 sa-sz i.t i.year if es2==1
estimates store m6
reg snpapersAA5y clusteringl5 dclusteringl5 femaleapi sa-sz i.t i.year if es2==1
estimates store m7
reg snpapersAA5y clusteringl5 dclusteringl5 femaleapi tpapersAAl5 sa-sz i.t i.year if es2==1
estimates store m8
reg snpapersAA5y ddegreel5 dclusteringl5 dstrengthppaperl5 degreel5 strengthppaperl5 clusteringl5 femaleapi  sa-sz i.t i.year if es2==1
estimates store m9
reg snpapersAA5y ddegreel5 dclusteringl5 dstrengthppaperl5 degreel5 strengthppaperl5 clusteringl5 femaleapi tpapersAAl5 sa-sz i.t i.year if es2==1
estimates store m10

suest m1 m2 m3 m4 m5 m6 m7 m8 m9 m10, noomitted  vce(cluster auth)
test [m1_mean]femaleapi = [m2_mean]femaleapi 
test [m1_mean]femaleapi = [m3_mean]femaleapi 
test [m1_mean]femaleapi = [m4_mean]femaleapi 
test [m1_mean]femaleapi = [m5_mean]femaleapi 
test [m1_mean]femaleapi = [m6_mean]femaleapi 
test [m1_mean]femaleapi = [m7_mean]femaleapi 
test [m1_mean]femaleapi = [m8_mean]femaleapi 
test [m1_mean]femaleapi = [m9_mean]femaleapi 
test [m1_mean]femaleapi = [m10_mean]femaleapi


test [m2_mean]femaleapi = [m3_mean]femaleapi 
test [m2_mean]femaleapi = [m4_mean]femaleapi 
test [m2_mean]femaleapi = [m5_mean]femaleapi 
test [m2_mean]femaleapi = [m6_mean]femaleapi 
test [m2_mean]femaleapi = [m7_mean]femaleapi 
test [m2_mean]femaleapi = [m8_mean]femaleapi 
test [m2_mean]femaleapi = [m9_mean]femaleapi 
test [m2_mean]femaleapi = [m10_mean]femaleapi


test [m3_mean]femaleapi = [m4_mean]femaleapi 


/*TABLE 4: Gender, Networks and Future output (AIS index)*/
drop es2
set more off


reg lsaisd5y degreel5 strengthppaperl5 clusteringl5 ddegreel5 dclusteringl5 dstrengthppaperl5 i.femaleapi lcaisdl5 sa-sz i.t i.year, vce(cluster auth)
gen es2=1 if e(sample)	   

set more off	 
  
reg lsaisd5y i.femaleapi sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sa-sz i.t i.year) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) replace

reg lsaisd5y i.femaleapi lcaisdl5 sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sa-sz i.t i.year) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lsaisd5y degreel5 ddegreel5 i.femaleapi sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sa-sz i.t i.year ddegreel5 ) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lsaisd5y degreel5 ddegreel5 i.femaleapi lcaisdl5 sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sa-sz i.t i.year ddegreel5 ) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lsaisd5y strengthppaperl5 dstrengthppaperl5 i.femaleapi sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sa-sz i.t i.year dstrengthppaperl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lsaisd5y strengthppaperl5 dstrengthppaperl5 i.femaleapi lcaisdl5 sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sa-sz i.t i.year dstrengthppaperl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lsaisd5y clusteringl5 dclusteringl5 i.femaleapi sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sa-sz i.t i.year dclusteringl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lsaisd5y clusteringl5 dclusteringl5 i.femaleapi lcaisdl5 sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sa-sz i.t i.year dclusteringl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lsaisd5y degreel5 strengthppaperl5 clusteringl5 ddegreel5 dclusteringl5 dstrengthppaperl5 i.femaleapi  sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sa-sz i.t i.year ddegreel5 dclusteringl5 dstrengthppaperl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lsaisd5y degreel5 strengthppaperl5 clusteringl5 ddegreel5 dclusteringl5 dstrengthppaperl5 i.femaleapi lcaisdl5 sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais, tex dec(3) drop(sa-sz i.t i.year ddegreel5 dclusteringl5 dstrengthppaperl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 


/*testing if the differences are statistically significant*/
reg lsaisd5y femaleapi sa-sz i.t i.year if es2==1
estimates store m1
reg lsaisd5y femaleapi lcaisdl5 sa-sz i.t i.year if es2==1
estimates store m2
reg lsaisd5y degreel5 ddegreel5 femaleapi sa-sz i.t i.year if es2==1
estimates store m3
reg lsaisd5y degreel5 ddegreel5 femaleapi lcaisdl5 sa-sz i.t i.year if es2==1
estimates store m4
reg lsaisd5y strengthppaperl5 dstrengthppaperl5 femaleapi sa-sz i.t i.year if es2==1
estimates store m5
reg lsaisd5y strengthppaperl5 dstrengthppaperl5 femaleapi lcaisdl5 sa-sz i.t i.year if es2==1
estimates store m6
reg lsaisd5y clusteringl5 dclusteringl5 femaleapi sa-sz i.t i.year if es2==1
estimates store m7
reg lsaisd5y clusteringl5 dclusteringl5 femaleapi lcaisdl5 sa-sz i.t i.year if es2==1
estimates store m8
reg lsaisd5y ddegreel5 dclusteringl5 dstrengthppaperl5 degreel5 strengthppaperl5 clusteringl5 femaleapi  sa-sz i.t i.year if es2==1
estimates store m9
reg lsaisd5y ddegreel5 dclusteringl5 dstrengthppaperl5 degreel5 strengthppaperl5 clusteringl5 femaleapi lcaisdl5  sa-sz i.t i.year if es2==1
estimates store m10

suest m1 m2 m3 m4 m5 m6 m7 m8 m9 m10, noomitted  vce(cluster auth)
test [m1_mean]femaleapi = [m2_mean]femaleapi 
test [m1_mean]femaleapi = [m3_mean]femaleapi 
test [m1_mean]femaleapi = [m4_mean]femaleapi 
test [m1_mean]femaleapi = [m5_mean]femaleapi 
test [m1_mean]femaleapi = [m6_mean]femaleapi 
test [m1_mean]femaleapi = [m7_mean]femaleapi 
test [m1_mean]femaleapi = [m8_mean]femaleapi 
test [m1_mean]femaleapi = [m9_mean]femaleapi 
test [m1_mean]femaleapi = [m10_mean]femaleapi


test [m2_mean]femaleapi = [m3_mean]femaleapi 
test [m2_mean]femaleapi = [m4_mean]femaleapi 
test [m2_mean]femaleapi = [m5_mean]femaleapi 
test [m2_mean]femaleapi = [m6_mean]femaleapi 
test [m2_mean]femaleapi = [m7_mean]femaleapi 
test [m2_mean]femaleapi = [m8_mean]femaleapi 
test [m2_mean]femaleapi = [m9_mean]femaleapi 
test [m2_mean]femaleapi = [m10_mean]femaleapi



/*Table 5*/
drop es2
set more off


reg lsaisd5y femaleapi  lavnetprodaisl5 dlavnetprodaisl5 avgcotl5 davgcotl5 degreel5 strengthppaperl5 clusteringl5 ddegreel5 dclusteringl5 dstrengthppaperl5 lcaisdl5 sa-sz i.t i.year, vce(cluster auth)
gen es2=1 if e(sample)	   

set more off
reg lsaisd5y i.femaleapi lavnetprodaisl5 dlavnetprodaisl5 sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais_netprod, tex dec(3) drop(sa-sz i.t i.year dlavnetprodaisl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) replace

reg lsaisd5y i.femaleapi lavnetprodaisl5 dlavnetprodaisl5 lcaisdl5 sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais_netprod, tex dec(3) drop(sa-sz i.t i.year dlavnetprodaisl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lsaisd5y i.femaleapi avgcotl5 davgcotl5 sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais_netprod, tex dec(3) drop(sa-sz i.t i.year davgcotl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lsaisd5y i.femaleapi avgcotl5 davgcotl5 lcaisdl5  sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais_netprod, tex dec(3) drop(sa-sz i.t i.year davgcotl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lsaisd5y i.femaleapi lavnetprodaisl5 dlavnetprodaisl5 avgcotl5 davgcotl5  sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais_netprod, tex dec(3) drop(sa-sz i.t i.year davgcotl5 dlavnetprodaisl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lsaisd5y i.femaleapi lavnetprodaisl5 dlavnetprodaisl5 avgcotl5 davgcotl5  lcaisdl5 sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais_netprod, tex dec(3) drop(sa-sz i.t i.year davgcotl5 dlavnetprodaisl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lsaisd5y i.femaleapi lavnetprodaisl5 dlavnetprodaisl5 avgcotl5 davgcotl5 degreel5 strengthppaperl5 clusteringl5 ddegreel5 dclusteringl5 dstrengthppaperl5 sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais_netprod, tex dec(3) drop(sa-sz i.t i.year davgcotl5 dlavnetprodaisl5 ddegreel5 dclusteringl5 dstrengthppaperl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 

reg lsaisd5y i.femaleapi lavnetprodaisl5 dlavnetprodaisl5 avgcotl5 davgcotl5 degreel5 strengthppaperl5 clusteringl5 ddegreel5 dclusteringl5 dstrengthppaperl5 lcaisdl5 sa-sz i.t i.year if es2==1, vce(cluster auth)
outreg2 using Tablefpapersais_netprod, tex dec(3) drop(sa-sz i.t i.year davgcotl5 dlavnetprodaisl5 ddegreel5 dclusteringl5 dstrengthppaperl5) label addtext(Career-time FE, YES, Year FE, YES, JEL codes shares, YES) 



/*testing if the differences are statistically significant*/
set more off
reg lsaisd5y  lcaisdl5 i.femaleapi sa-sz i.t i.year if es2==1
estimates store m1
reg lsaisd5y  i.femaleapi sa-sz i.t i.year if es2==1
estimates store m2
reg lsaisd5y lavnetprodaisl5 dlavnetprodaisl5 i.femaleapi sa-sz i.t i.year if es2==1
estimates store m3
reg lsaisd5y lavnetprodaisl5 dlavnetprodaisl5 i.femaleapi lcaisdl5 sa-sz i.t i.year if es2==1
estimates store m4
reg lsaisd5y avgcotl5 davgcotl5 i.femaleapi sa-sz i.t i.year if es2==1
estimates store m5
reg lsaisd5y avgcotl5 davgcotl5 i.femaleapi sa-sz i.t i.year lcaisdl5 if es2==1
estimates store m6
reg lsaisd5y avgcotl5 davgcotl5 lavnetprodaisl5 dlavnetprodaisl5 i.femaleapi sa-sz i.t i.year if es2==1
estimates store m7
reg lsaisd5y avgcotl5 davgcotl5 lavnetprodaisl5 dlavnetprodaisl5 i.femaleapi sa-sz i.t i.year lcaisdl5 if es2==1
estimates store m8
reg lsaisd5y i.femaleapi lavnetprodaisl5 dlavnetprodaisl5 avgcotl5 davgcotl5 degreel5 strengthppaperl5 clusteringl5 ddegreel5 dclusteringl5 dstrengthppaperl5 i.femaleapi sa-sz i.t i.year if es2==1
estimates store m9
reg lsaisd5y i.femaleapi lavnetprodaisl5 dlavnetprodaisl5 avgcotl5 davgcotl5 degreel5 strengthppaperl5 clusteringl5 ddegreel5 dclusteringl5 dstrengthppaperl5 i.femaleapi lcaisdl5 sa-sz i.t i.year if es2==1
estimates store m10

suest m1 m2 m3 m4 m5 m6 m7 m8 m9 m10, noomitted  vce(cluster auth)
test [m1_mean]1.femaleapi  = [m3_mean]1.femaleapi 
test [m1_mean]1.femaleapi  = [m4_mean]1.femaleapi  
test [m1_mean]1.femaleapi  = [m5_mean]1.femaleapi  
test [m1_mean]1.femaleapi  = [m6_mean]1.femaleapi 
test [m1_mean]1.femaleapi  = [m7_mean]1.femaleapi 
test [m1_mean]1.femaleapi  = [m8_mean]1.femaleapi 
test [m1_mean]1.femaleapi  = [m9_mean]1.femaleapi 
test [m1_mean]1.femaleapi  = [m10_mean]1.femaleapi 


test [m2_mean]1.femaleapi = [m3_mean]1.femaleapi 
test [m2_mean]1.femaleapi = [m4_mean]1.femaleapi
test [m2_mean]1.femaleapi = [m5_mean]1.femaleapi 
test [m2_mean]1.femaleapi = [m6_mean]1.femaleapi
test [m2_mean]1.femaleapi = [m7_mean]1.femaleapi
test [m2_mean]1.femaleapi = [m8_mean]1.femaleapi
test [m2_mean]1.femaleapi = [m9_mean]1.femaleapi
test [m2_mean]1.femaleapi = [m10_mean]1.femaleapi


/************************************FIGURES*************************************/
******************************************************************************	   
/*FIGURES*/
*Figure 1: Participation of Women: 1970-2017
set more off
import delimited "networkgender7017.csv", clear
drop if nauthors<0
drop if year<1970
drop  journalid prod
drop a-z
bys articleid: gen t=_n
reshape long auth femaleapi, i(articleid t) j(n)
drop if auth==.
panels auth if femaleapi==1 & year==1970
gen nfemale=r(N_g)
panels auth if femaleapi==0 & year==1970
gen nmale=r(N_g)
gen total=nfemale+nmale if year==1970
gen w=nfemale/total if year==1970
gen wm=nmale/total if year==1970
set more off
forvalues i=1971(1)2017{
panels auth if femaleapi==1 & year==`i'
replace nfemale=r(N_g)
panels auth if femaleapi==0 & year==`i'
replace nmale=r(N_g)
replace total=nfemale+nmale if year==`i'
replace w=nfemale/total if year==`i'
replace wm=nmale/total if year==`i'
}
keep year w wm
duplicates drop
tsset year, yearly
tsline w if year<2017, lcolor(black) lwidth(thick) lpattern(solid) ytitle("Fraction of women") xtitle("Year") legend(label(1 female) label(2 male)) scheme(s1color)	
graph export "wft.pdf", as(pdf) replace



*Figure 2: research output over time

use "auth7017fields5y.dta", clear

/*Restricting the sample to the estimated in Table 2 and the rest of the paper)*/
drop if ystart<1974
reg saisd5y female i.t i.year sa-sz, cluster(auth)  /*KY time invariant quality, not presented in the paper*/
keep if e(sample)


collapse (mean) saisd5y snpapersAA5y snpapers5y degree clustering strengthppaper, by(year female)

drop if female==.
reshape wide saisd5y snpapersAA5y snpapers5y degree clustering strengthppaper, i(year) j(female)

gen mprod5diff=saisd5y1-saisd5y0
gen mpapersdiff=snpapers5y1-snpapers5y0
gen mpapersAA5diff=snpapersAA5y1-snpapersAA5y0

gen degreediff=degree1-degree0
gen clusterdiff=clustering1-clustering0
gen strengthdiff=strengthppaper1-strengthppaper0


/*Output differences over time*/

/*Figure 2 a)*/

tsset year, yearly
drop if year<1980 /*to be consistent with the adjusted differences*/
drop if year==2017 /*This year is incomplete*/

 twoway (tsline snpapers5y0, color(blue) lpattern(dash_dot) lwidth(thick)) ///
       (tsline snpapers5y1, lpattern(shortdash) lwidth(thick)) ///
	   (tsline mpapersdiff,  color(black) lwidth(thick)) if year<2017, ///
       ytitle("Avg. # of publications per author") ///
	    xlabel(1980(5)2015) ///
		yline(0, lpattern(shortdash) lcolor(gray)) ///
		ylabel(-1(1)4) ///
       xtitle("Year")  legend(order(1 "Male" 2 "Female" 3 "(Female-Male)")) scheme(s1color) title("")
graph export "snpapers5diffb.pdf", as(pdf) replace

/*Figure 2 c)*/
twoway (tsline snpapersAA5y0, color(blue) lpattern(dash_dot) lwidth(thick)) ///
       (tsline snpapersAA5y1, lpattern(dash) lwidth(thick)) ///
	   (tsline mpapersAA5diff,  color(black) lwidth(thick)), ///
       ytitle("Avg. # of top 5 publications per author") ///
	    xlabel(1980(5)2015) ///
		ylabel(-0.2(0.1)0.3) ///
		yline(0, lpattern(shortdash) lcolor(gray)) ///
       xtitle("Year")  legend(order(1 "Male" 2 "Female" 3 "(Female-Male)")) scheme(s1color) title("")
graph export "snpapersAA5difftib.pdf", as(pdf) replace

/*Figure 2 e)*/
tsset year, yearly
twoway (tsline saisd5y0, color(blue) lpattern(dash_dot) lwidth(thick)) ///
       (tsline saisd5y1, lpattern(shortdash) lwidth(thick)) ///
	   (tsline mprod5diff, color(black) lwidth(thick)), ///
       ytitle("Average Research Output") ///
	    xlabel(1980(5)2015) ///
		ylabel(-4(2)8) ///
		yline(0, lpattern(shortdash) lcolor(gray)) ///
       xtitle("Year")  legend(order(1 "Male" 2 "Female" 3 "(Female-Male)")) scheme(s1color) 
graph export "prod5diffaisb.pdf", as(pdf) replace



/*Figure 3: Network differences across time - unadjusted mean*/
/*Figure 3 a)*/
twoway (tsline degree0, color(blue) lpattern(dash_dot) lwidth(thick)) ///
       (tsline degree1, lpattern(dash) lwidth(thick)) ///
	   (tsline degreediff,  color(black) lwidth(thick)), ///
       ytitle("Degree") ///
	    xlabel(1980(5)2015) ///
		yline(0, lpattern(shortdash) lcolor(gray)) ///
		ylabel(-1(1)4) ///
       xtitle("Year")  legend(order(1 "Male" 2 "Female" 3 "(Female-Male)")) scheme(s1color) title("")
graph export "degreediffb.pdf", as(pdf) replace

/*Figure 3 c)*/
twoway (tsline clustering0, color(blue) lpattern(dash_dot) lwidth(thick)) ///
       (tsline clustering1, lpattern(dash) lwidth(thick)) ///
	   (tsline clusterdiff,  color(black) lwidth(thick)), ///
       ytitle("Clustering") ///
	    xlabel(1980(5)2015) ///
		ylabel(0(0.2)0.8) ///
		yline(0, lpattern(shortdash) lcolor(gray)) ///
       xtitle("Year")  legend(order(1 "Male" 2 "Female" 3 "(Female-Male)")) scheme(s1color) title("")
graph export "clusterdiffb.pdf", as(pdf) replace

/*Figure 3 e)*/
twoway (tsline strengthppaper0, color(blue) lpattern(dash_dot) lwidth(thick)) ///
       (tsline strengthppaper1, lpattern(dash) lwidth(thick)) ///
	   (tsline strengthdiff,  color(black) lwidth(thick)), ///
       ytitle("Strength") ///
	    xlabel(1980(5)2015) ///
		ylabel(0(0.2)0.8) ///
		yline(0, lpattern(shortdash) lcolor(gray)) ///
       xtitle("Year")  legend(order(1 "Male" 2 "Female" 3 "(Female-Male)")) scheme(s1color) title("")
graph export "strengthdiffb.pdf", as(pdf) replace

/*Figure 2 and 3: Adjusted means over time*/

use auth7017fields5y,clear

set more off
xtset auth year, yearly

/*Regressions to obtain the adjusted means differences*/

reg snpapers5y i.femaleapi##i.year i.t sa-sz if year>1979, cluster(auth)  /*total number of papers*/
parmest, saving(papersacrossyear_pols, replace)
margins femaleapi, at(year=1980 year=1995 year=2016)
testparm femaleapi#year /*significant at 1: 0.0000%*/


reg snpapersAA5y i.femaleapi##i.year i.t sa-sz if year>1979, cluster(auth)  /*top 5*/
parmest, saving(papersAAacrossyear_pols, replace)
margins femaleapi, at(year=1980 year=2000 year=2016)
testparm femaleapi#year /*significant at 1: 0.0010%*/

reg saisd5y i.femaleapi##i.year i.t  sa-sz if year>1979, cluster(auth)  /*AIS quality measure*/
parmest, saving(aisacrossyear_pols, replace)
margins femaleapi, at(year=1980 year=2008 year=2016)
testparm femaleapi#year /*significant at 1: 0.0000%*/

reg degree ddegree i.femaleapi##i.year i.t sa-sz if year>1979, vce(cluster auth)  
margins femaleapi, at(year=1980 year=2017)
parmest, saving(degreeacrossyear_pols, replace)
testparm femaleapi#year /*significant at 1: 0.0000%*/

reg strengthppaper dstrengthppaper i.femaleapi##i.year i.t sa-sz if year>1979, vce(cluster auth)
parmest, saving(strengthacrossyear_pols, replace)
testparm femaleapi#year /*significant at 1: 0.0001%*/

reg clustering dclustering i.femaleapi##i.year i.t sa-sz if year>1979, vce(cluster auth)
parmest, saving(clusteringacrossyear_pols, replace)
testparm femaleapi#year


/*PLOTS*/
/*Figure 2 b)*/
use papersacrossyear_pols, clear
split parm, p("#")
keep if parm1=="1.femaleapi"
drop if parm=="1.femaleapi"
gen year=1981+(_n-1)
label variable year "Year"
eclplot estimate min95 max95 year if year>1979 & year<2017, ciopts(blcolor(red)) estopts(color(black)) graphregion(color(white)) note("") xtitle("Year") xlabel(1980(5)2015) ytitle("Changes in the gender gap") yline(0, lcolor("gray") lpattern(shortdash)) title("") ylabel(-1(0.4)0.6)
graph export papers_pols.pdf, replace


/*Figure 2 d)*/
use papersAAacrossyear_pols, clear
split parm, p("#")
keep if parm1=="1.femaleapi"
drop if parm=="1.femaleapi"
gen year=1981+(_n-1)
label variable year "Year"
eclplot estimate min95 max95 year if year>1979 & year<2017, ciopts(blcolor(red)) estopts(color(black)) graphregion(color(white)) note("") xtitle("Year") xlabel(1980(5)2015) ytitle("Changes in the gender gap") yline(0, lcolor("gray") lpattern(shortdash)) title("") ylabel(-0.2(0.1)0.2)
graph export papersAA_pols.pdf, replace

/*Figure 2 f)*/
use aisacrossyear_pols, clear
split parm, p("#")
keep if parm1=="1.femaleapi"
drop if parm=="1.femaleapi"
gen year=1981+(_n-1)
label variable year "Year"
eclplot estimate min95 max95 year if year>1979 & year<2017, ciopts(blcolor(red)) estopts(color(black)) graphregion(color(white)) note("") xtitle("Year") xlabel(1980(5)2015) ytitle("Changes in the gender gap") yline(0, lcolor("gray") lpattern(shortdash)) title("") ylabel(-1(1)4)
graph export ais_pols.pdf, replace


/*Figure 3 b)*/
use degreeacrossyear_pols, clear
split parm, p("#")
keep if parm1=="1.femaleapi"
drop if parm=="1.femaleapi"
gen year=1981+(_n-1)
label variable year "Year"
eclplot estimate min95 max95 year if year>1979 & year<2017, ciopts(blcolor(red)) estopts(color(black)) graphregion(color(white)) note("") xtitle("Year") xlabel(1980(5)2015) ytitle("Changes in the gender gap") yline(0, lcolor("gray") lpattern(shortdash)) title("") ylabel(-1.5(0.5)1)
graph export degdiff_pols.pdf, replace

/*Figure 3 d)*/
use clusteringacrossyear_pols, clear
split parm, p("#")
keep if parm1=="1.femaleapi"
drop if parm=="1.femaleapi"
gen year=1981+(_n-1)
label variable year "Year"
eclplot estimate min95 max95 year if year>1979 & year<2017, ciopts(blcolor(red)) estopts(color(black)) graphregion(color(white)) note("") xtitle("Year") xlabel(1980(5)2015) ytitle("Changes in the gender gap") yline(0, lcolor("gray") lpattern(shortdash)) title("") ylabel(-0.2(0.1)0.2)
graph export clustdiff_pols.pdf, replace

/*Figure 3 f)*/
use strengthacrossyear_pols, clear
split parm, p("#")
keep if parm1=="1.femaleapi"
drop if parm=="1.femaleapi"
gen year=1981+(_n-1)
label variable year "Year"
eclplot estimate min95 max95 year if year>1979 & year<2017, ciopts(blcolor(red)) estopts(color(black)) graphregion(color(white)) note("") xtitle("Year") xlabel(1980(5)2015) ytitle("Changes in the gender gap") yline(0, lcolor("gray") lpattern(shortdash)) title("") ylabel(-0.2(0.1)0.2)
graph export istdiffb_pols.pdf, replace

	   
	   
	   

	   

